﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
  public  class SYS_Label_LabelRelDAL
    {
        private string DbName;

        public SYS_Label_LabelRelDAL()
        {
            DbName = "JudgeDoc";
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool AddSysLabelRel(SYS_Label_LabelRel Model, string username)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" insert into SYS_Label_LabelRel(LLR_ID,LLR_LawLabelID,LLR_LawLabelName,LLR_FactLabelXpath,LLR_CaseCauseID,UpdateTime) values (@LLR_ID,@LLR_LawLabelID,@LLR_LawLabelName,@LLR_FactLabelXpath,@LLR_CaseCauseID,getdate()) ");
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            oBase.AddInParameter(oCmd, "@LLR_ID", DbType.String, Model.LLR_ID);
            oBase.AddInParameter(oCmd, "@LLR_LawLabelID", DbType.String, Model.LLR_LawLabelID);
            oBase.AddInParameter(oCmd, "@LLR_LawLabelName", DbType.String, Model.LLR_LawLabelName);
            oBase.AddInParameter(oCmd, "@LLR_FactLabelXpath", DbType.String, Model.LLR_FactLabelXpath);
            oBase.AddInParameter(oCmd, "@LLR_CaseCauseID", DbType.String, Model.LLR_CaseCauseID);
            //oBase.AddInParameter(oCmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                //OperLogDAL.AddOperLog(username, "insert", "SYS_Label_LabelRel", String.Format("CC_ID='{0}'", Model.LLR_ID).ToString());

                return true;
            }
            return false;
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string LLR_LawLabelID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SYS_Label_LabelRel where LLR_LawLabelID=@LLR_LawLabelID ");

            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());

            oBase.AddInParameter(oCmd, "@LLR_LawLabelID", DbType.String, LLR_LawLabelID);

            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }


    }
}
